package com.wuye.basic.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wuye.basic.domain.WyOwner;
import com.wuye.basic.domain.dto.WyHomeDTO;
import com.wuye.basic.service.IWyOwnerService;
import com.wuye.common.core.page.PageDomain;
import com.wuye.common.core.page.TableSupport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.basic.domain.WyHome;
import com.wuye.basic.service.IWyHomeService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 房间资料Controller
 * 
 * @author jack
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/basic/home")
public class WyHomeController extends BaseController
{
    @Autowired
    private IWyHomeService wyHomeService;
 	@Autowired
    private IWyOwnerService wyOwnerService;

    /**
     * 查询房间资料列表
     */
    @PreAuthorize("@ss.hasPermi('basic:home:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyHomeDTO wyHomeDTO)
    {
        
       return wyHomeService.selectInfo(wyHomeDTO);
    }

    /**
     * 导出房间资料列表
     */
    @PreAuthorize("@ss.hasPermi('basic:home:export')")
    @Log(title = "房间资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyHome wyHome)
    {
        List<WyHome> list = wyHomeService.selectWyHomeList(wyHome);
        ExcelUtil<WyHome> util = new ExcelUtil<WyHome>(WyHome.class);
        util.exportExcel(response, list, "房间资料数据");
    }

    /**
     * 获取房间资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:home:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyHomeService.getInfoById(id));
    }

    /**
     * 新增房间资料
     */
    @PreAuthorize("@ss.hasPermi('basic:home:add')")
    @Log(title = "房间资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyHomeDTO wyHomeDTO)
    {
        return toAjax(wyHomeService.insert(wyHomeDTO));
    }

    /**
     * 修改房间资料
     */
    @PreAuthorize("@ss.hasPermi('basic:home:edit')")
    @Log(title = "房间资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyHomeDTO wyHomeDTO)
    {
        return toAjax(wyHomeService.edit(wyHomeDTO));
    }

    /**
     * 删除房间资料
     */
    @PreAuthorize("@ss.hasPermi('basic:home:remove')")
    @Log(title = "房间资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyHomeService.deleteBatchIds(Arrays.asList(ids)));
    }

    /**
     * 查询房间资料列表
     */
    @PreAuthorize("@ss.hasPermi('basic:home:list')")
    @PostMapping("/homeList")
    public TableDataInfo homeList(@RequestBody List<Long> homeIds)
    {
        startPage();
        QueryWrapper<WyHome> wrapper = new QueryWrapper<>();
        wrapper.in("homeId", homeIds);
        List<WyHome> list = wyHomeService.list(wrapper);
        for (WyHome item : list){
            WyOwner owner = wyOwnerService.selectWyOwnerByOwnerId(item.getOwnerId());
            item.setOwner(owner);
        }
        return getDataTable(list);
    }

}
